import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import knowledge from './modules/knowledge'
import quickReply from './modules/quickReply'

const constantRoutes = [
    {
        path: '/login',
        component: () => import('@/view/login/index.vue'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/view/error-page/404'),
        hidden: true
    },
    {
        path: '/403',
        component: () => import('@/view/error-page/403'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        name: 'index',
        redirect: '/login',
        meta: {
            title: '首页',
            icon: 'table'
        },
        hidden: true
    }
]

export const asyncRoutes = [
    knowledge,
    quickReply
]

const createRouter = () => new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
